<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';

const { t } = useI18n<{ message: typeof import('../../locales/en-US').default }>();

const emit = defineEmits<{
  close: [];
  save: [settings: { pageNum: number; pageSize: number }];
}>();

const pageNum = ref(1);
const pageSize = ref(100);

onMounted(() => {
  // 从本地存储加载设置
  const savedSettings = localStorage.getItem('knowledgeBaseSettings');
  if (savedSettings) {
    const settings = JSON.parse(savedSettings);
    pageNum.value = settings.pageNum;
    pageSize.value = settings.pageSize;
  }
});

const handleSave = () => {
  const settings = {
    pageNum: pageNum.value,
    pageSize: pageSize.value
  };
  // 保存到本地存储
  localStorage.setItem('knowledgeBaseSettings', JSON.stringify(settings));
  emit('save', settings);
  emit('close');
};
</script>

<template>
  <div class="modal">
    <div class="modal-content">
      <h2>{{ t('settings.title') }}</h2>
      <div class="form-group">
        <label>{{ t('settings.pageSize') }}</label>
        <input 
          type="number" 
          v-model="pageSize" 
          min="1" 
          max="1000"
        >
      </div>
      <div class="form-group">
        <label>{{ t('settings.pageNum') }}</label>
        <input 
          type="number" 
          v-model="pageNum" 
          min="1"
        >
      </div>
      <div class="modal-actions">
        <button class="cancel-btn" @click="$emit('close')">{{ t('common.cancel') }}</button>
        <button class="confirm-btn" @click="handleSave">{{ t('common.save') }}</button>
      </div>
    </div>
  </div>
</template>

<style scoped>
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: white;
  padding: 24px;
  border-radius: 8px;
  width: 400px;
}

.modal-content h2 {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 600;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
}

.form-group input {
  width: 100%;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 24px;
}

.cancel-btn,
.confirm-btn {
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
}

.cancel-btn {
  background-color: #f3f4f6;
  border: none;
}

.confirm-btn {
  background-color: #3b82f6;
  color: white;
  border: none;
}
</style>